/*
 * Stepper.cpp
 *
 *  Created on: Mar 4, 2012
 *      Author: trwulff
 */
#ifndef STEPPER_CPP
#define STEPPER_CPP
#include "Stepper.hpp"

/*
 * Default constructor
 */
	Stepper::Stepper(double jogtimeon)
	{
		StepTimeOn=jogtimeon;
		StepTimeOff=jogtimeon;
		IsEnd=true;
		StepSpeed0=DEFAULTSTEPSPEED;
		
	}
	Stepper::Stepper(double jogtimeon,double jogtimeoff)
	{
		StepTimeOn=jogtimeon;
		StepTimeOff=jogtimeoff;
		IsEnd=true;
		StepSpeed0=DEFAULTSTEPSPEED;
	}

	/*
	 * Default destructor
	 */
	Stepper::~Stepper(){}
	void Stepper::SetStepSpeed(float speed)
	{
		StepSpeed0=speed;
	}
	float Stepper::GetCurrentSpeed(float speed)
	{
		if(!IsEnd)
		{
			if(StepTimer.Get()<StepTimeOn)return StepSpeed;
			if((StepTimer.Get()>=StepTimeOn)&&(StepTimer.Get()<(StepTimeOn+StepTimeOff)))return 0.0;
			if((StepTimer.Get()>(StepTimeOn+StepTimeOff)))
			{
				IsEnd=true;
				StepTimer.Stop();
			}
		}
			
			return speed;
	}
	void Stepper::Restart(float speed)
	{
		if(IsEnd)
			{
			if(speed>=0.0)StepSpeed=StepSpeed0;
			if(speed<0.0)StepSpeed=-StepSpeed0;
			IsEnd=false;
			StepTimer.Reset();
			StepTimer.Start();
			}
	}



#endif

